/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ftpcombiner.logger;

import ftpcombiner.gui.GUIResources;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.text.SimpleDateFormat;

/**
 *
 * @author Gary
 */
public class Logger {

    private static File logFile;
    private static PrintStream logStream;

    public static void setUpLogging() {
        if (System.console() == null) {
            logFile = new File(GUIResources.getInstance().getPropertiesFile().getParentFile().getPath() + "\\log_" + (new SimpleDateFormat("yyyy-MMM-dd_HH.mm.ss")).format(System.currentTimeMillis()) + ".txt");
            try {
                if (!logFile.exists()) {
                    logFile.createNewFile();
                }
            } catch (IOException ex) {
                System.out.println(ex);
            }
            
            try {
                logStream = new PrintStream(logFile);
            } catch (FileNotFoundException ex) {
                System.err.println(ex);
            }
            System.setOut(logStream);
            System.setErr(logStream);
        } 
    }
    public static void close(){
        if(logStream != null){
            logStream.close();
        }
    }
}
